package com.jzr.bedside.controller.api;

import com.jzr.bedside.db1.service.TAppVersionService;
import com.jzr.bedside.db1.vo.AppVersionVo;
import com.jzr.common.BaseController;
import com.jzr.common.entity.vo.Result;
import com.jzr.common.util.UrlUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "APP版本信息接口")
@RestController
@RequestMapping("/api/appVersion")
public class AppVersionController extends BaseController {
    @Autowired
    TAppVersionService appVersionService;

    @Value("${file.app-download-url}")
    private String appDownloadUrl;

    @ApiOperation("获取最新版本")
    @GetMapping("/lastVersion")
    public Result<AppVersionVo> lastVersion(@ApiParam("软件类型") Integer softType ){
        if(softType == null){
            return Result.fail("请输入softType");
        }
        AppVersionVo AppVersionVo = appVersionService.lastVersion(softType);
        String softName = AppVersionVo.getSoftName() == null ? "" : AppVersionVo.getSoftName();

        AppVersionVo.setAccessUrl(UrlUtil.concat(appDownloadUrl, softName));

        return Result.success("成功", AppVersionVo);
    }


}
